import request from "@/utils/request";
import type {
  GetUserListParams,
  GetUserListResponse,
  AddUserParams,
  UpdateUserParams,
  GetUserRoleListResponse,
} from "./type/userType";
const enum Api {
  getUserList = "/admin/acl/user",
  addUser = "/admin/acl/user/save",
  updateUser = "/admin/acl/user/update",
  removeUser = "/admin/acl/user/remove",
  getUserRoleList = "/admin/acl/user/toAssign",
  assignUserRoleList = "/admin/acl/user/doAssign",
}
// 获取管理用户列表
export const getUserListApi = ({
  page,
  limit,
  username,
}: GetUserListParams) => {
  return request.get<any, GetUserListResponse>(
    Api.getUserList + `/${page}/${limit}`,
    {
      params: {
        username,
      },
    }
  );
};
// 添加管理用户
export const addUserApi = (data: AddUserParams) => {
  return request.post<any, null>(Api.addUser, data);
};
// 修改管理用户
export const updateUserApi = (data: UpdateUserParams) => {
  return request.put<any, null>(Api.updateUser, data);
};
// 删除管理用户
export const removeUserApi = (id: string) => {
  return request.delete<any, null>(Api.removeUser + `/${id}`);
};
// 获取角色数据
export const getUserRoleListApi = (userId: string) => {
  return request.get<any, GetUserRoleListResponse>(
    Api.getUserRoleList + `/${userId}`
  );
};
// 分配角色
export const assignUserRoleListApi = (userId: string, roleId: string[]) => {
  return request.post<any, null>(
    Api.assignUserRoleList,
    {},
    {
      params: {
        userId,
        roleId: roleId.join(","),
      },
    }
  );
};
